package com.hongye.broker.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hongye.broker.mapper.BrokerMapper;
import com.hongye.broker.mapper.FuncationMapper;
import com.hongye.broker.service.BrokerService;
import com.hongye.broker.vo.BrokerLoginVo;
import com.hongye.broker.vo.HouseVo;
import com.hongye.common.entity.BrokerEntity;
import com.hongye.common.entity.FuncationEntity;
import com.hongye.common.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hongye.broker.mapper.GroupMapper;
import com.hongye.broker.service.GroupService;
import com.hongye.common.entity.GroupEntity;
import com.hongye.common.entity.HouseEntity;
import org.springframework.transaction.annotation.Transactional;

@Service("BrokerService")
public class BrokerServiceImpl extends ServiceImpl<BrokerMapper,BrokerEntity> implements BrokerService {
    @Autowired
    private BrokerMapper brokerMapper;
    @Autowired
    private FuncationMapper funcationMapper;

    @Override
    public BrokerEntity findBrokerPhone(String phone) {
        return brokerMapper.findBrokerPhone(phone);
    }

    @Override
    @Transactional
    public ResponseResult brokerLogin(BrokerEntity brokerEntity) {
        BrokerLoginVo brokerLoginVo = new BrokerLoginVo();
        //填充数据
        brokerLoginVo.setBrokerImg(brokerEntity.getImage());
        brokerLoginVo.setBrokerName(brokerEntity.getBrokerName());

        ArrayList<HouseVo> houselist = new ArrayList<>();
        HouseVo houseVo = new HouseVo();
        HouseVo houseVo2 = new HouseVo();
        HouseVo houseVo3 = new HouseVo();

        houseVo.setHouseName("新房");
        houseVo.setHouseNum(brokerEntity.getNewhomeSales());
        houseVo2.setHouseName("二手房");
        houseVo2.setHouseNum(brokerEntity.getSechomeSales());
        houseVo3.setHouseName("租房");
        houseVo3.setHouseNum(brokerEntity.getRenthomeSales());
        houselist.add(houseVo);
        houselist.add(houseVo2);
        houselist.add(houseVo3);
        //查询全部功能
        List<FuncationEntity> list = funcationMapper.findAll();
        brokerLoginVo.setHouseVos(houselist);
        brokerLoginVo.setBrokerTypeVos(list);

        //返回
        HashMap<String, Object> map = new HashMap<>();
        map.put("brokerLogin", brokerLoginVo);
        return new ResponseResult(1, "登录成功", map);
    }

    @Override
    public List<BrokerEntity> phb(String brokerName) {
        QueryWrapper<BrokerEntity> queryWrapper = Wrappers.query();
        queryWrapper.orderByDesc("newhome_sales");
        queryWrapper.like("broker_name",brokerName);
        List<BrokerEntity> list = this.list(queryWrapper);
        return list;
    }

}
